﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
using System.Data.SqlClient;
public partial class Deparment_Worker_Deparment_meeting : System.Web.UI.Page
{


    public string TableName, strFields, strConditions, mKey, strAccount_TYPE, strAccount_AC_SORT;
    private long strAccount_ID;
    public int Pagesize, PageIndex, PageCount;
    string strSql, delWithinInfoId;
    private System.Data.DataTable dt;

    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumDeparment);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            strAccount_TYPE = _Account.Type;
            strAccount_ID = _Account.AccountId;
            strAccount_AC_SORT = _Account.AC_SORT;

            if (Request.Form["btnSubmit"] == "删除")
            {
                DeleteInfo();
            }
            ShowDate();
        }
    }


    /// <summary>
    /// 删除信息
    /// </summary>
    private void DeleteInfo()
    {
        int dlLength = GridView1.Rows.Count;
        if (dlLength > 0)
        {
            string deid = Request.Form["chk"].ToString();
            string strdelet = "delete D_Meeting where D_MeetingID in(" + deid.Trim() + ") and accountid=" + strAccount_ID;
            Db db = new Db();
            db.Command(strdelet);
            db.Close();
            Response.Write("<script>alert('成功删除！')</script>");
            ShowDate();
        }
    }


    public void ShowDate()
    {
        Db db = new Db();
        DbPage dbPage = new DbPage(db);
        dbPage.Table = "D_Meeting ";                                               //要查询的表明
        dbPage.Key = "D_MeetingID";                                               //表的主键    
        dbPage.Where = fctConditions();                                           //查询条件    
        dbPage.SelectField = "D_MeetingID,convert(varchar(100),AddDate,23) as AddDate ,Title, Content";//要显示的字段
        dbPage.PageIndex = SysFun.ToInt(Request["CurrentlyPageIndex"]);          //要显示第几页   
        dbPage.PageSize = 10;                                                    //没有显示记录条数   
        dbPage.OrderBy = "D_MeetingID ";                  //排序字段
        dbPage.OrderByIsDesc = true;
        dt = dbPage.DataTable(60);
        GridView1.DataSource = dt;
        GridView1.Columns[4].Visible = true;
        GridView1.DataBind();
        GridView1.Columns[4].Visible = false;
        dbPage.Db.Close();
        db.Close();
        this.DbPageFlip1.DbPage = dbPage;//将数据传给控键

    }
    /// <summary>
    /// 生成查询条件
    /// </summary>
    /// <returns></returns>
    public string fctConditions()
    {
        string strtemp = " accountid=" + strAccount_ID, Title;
        Title = txtTitle.Text.Trim();
        if (Title != "")
        {
            strtemp += " and Title like '" + Title + "'";
        }

        return strtemp;
    }

    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            if (((Label)(e.Row.Cells[2].Controls[1])).Text.Trim().Length > 30)
            {
                e.Row.Cells[2].Text = "<a href='Worker/Meeting_show.aspx?D_MeetingID=" + SysFun.PasswordEncrypt(e.Row.Cells[4].Text.Trim()) + "' target='_black'>" + SysFun.StringInterceptFill(((Label)(e.Row.Cells[2].Controls[1])).Text.Trim(), 28) + "..." + "</a>";
            }
            else//   <input id="Button1" type="button" value="button" onclick="javascript:open('')" />
            {
                e.Row.Cells[2].Text = "<a href='Worker/Meeting_show.aspx?D_MeetingID=" + SysFun.PasswordEncrypt(e.Row.Cells[4].Text.Trim()) + "'  target='_black'>" + ((Label)(e.Row.Cells[2].Controls[1])).Text.Trim() + "</a>";
            }

            e.Row.Cells[5].Text = " <a href='../Deparment/Worker/Meeting_update.aspx?D_MeetingID=" + SysFun.PasswordEncrypt(e.Row.Cells[4].Text.Trim()) + "'  target='_black'>修改</a>";

        }
    }
}
